﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using javanet_demo.Models;
using JavaNET.mvc;
using javanet_demo.demo;
using JavaNET.exception;

namespace javanet_demo.Controllers
{
    public class AccountController : Controller
    {
        [JavaNETFacade]
        private AccountFacade accountFacade;

        //
        // GET: /Account/LogOn

        public ActionResult LogOn()
        {
            return View();
        }

        //
        // POST: /Account/LogOn

        [HttpPost]
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            try
            {
                String fullName = accountFacade.login(model.UserName, model.Password);
                FormsAuthentication.SetAuthCookie(fullName, model.RememberMe);
                return RedirectToAction("Index", "Home");
            }
            catch (JavaNETException e)
            {
                ModelState.AddModelError("", e.errorMessage);
                return View(model);
            }
        }

        //
        // GET: /Account/LogOff

        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();

            return RedirectToAction("Index", "Home");
        }

    }
}
